import count from '@dfeidao/atom-nodejs/db/count';
import operate from '@dfeidao/atom-nodejs/db/operate';
// import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';


interface Message {
	productid: string;
	tenant_name1: string;
	tenant_name: string;
	link_man?: string;
	phone?: string;
	email?: string;
	tenantid: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string) {

	const { update, exec } = operate(action_id, session_id, '12');
	if (msg.tenant_name1 !== msg.tenant_name) {
		const c = count(action_id, session_id, '12');
		c.prepare('pub_tenant', { productid: msg.productid, tenant_name: msg.tenant_name });
		const [t] = await c.exec();
		if (t > 0) {
			return 'other';
		}
	}
	update('pub_tenant', { tenantid: msg.tenantid, productid: msg.productid }, { tenantid: msg.tenantid, tenant_name: msg.tenant_name, link_man: msg.link_man, phone: msg.phone, email: msg.email });

	const res = await exec();

	// 添加操作日志
	// “张三”在[产品类型]页面“新增”了一条编号为“LX0000001”的数据

	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}

}
